package com.cn.bulu.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cn.bulu.dao.WalletRecordDao;
import com.cn.bulu.pojo.WalletRecord;
import com.cn.bulu.service.WalletRecordService;
/**
 * 
 * @author XGH
 *
 */
@Service("walletRecordService")
public class WalletRecordServiceImpl implements WalletRecordService{
	
	@Resource
	private WalletRecordDao walletRecordDao;
	
	@Override
	public int insertWalletRecord(Integer peopleId, Integer indentId, Integer peopleType,
			Double mainMoney, Double addMoney, Double subMoney, Double finalGetMoney, Double finalLostMoney,
			Integer type,Integer status, String remark, Integer isDelete, String mentod) {
		
		WalletRecord walletRecord = getInsertWallet( peopleId,indentId,peopleType,mainMoney,addMoney,
				subMoney, finalGetMoney, finalLostMoney,type,status, remark, isDelete,mentod);
		
		walletRecordDao.insertWalletRecord(walletRecord);
		
		int result = walletRecord.getWalletRecordId();
		
		return result;
	}
	
	//2017-5-5 XGH 将钱包明细封装
	private WalletRecord getInsertWallet(Integer peopleId, Integer indentId, Integer peopleType, Double mainMoney,
			Double addMoney, Double subMoney, Double finalGetMoney, Double finalLostMoney, Integer type,
			Integer status, String remark, Integer isDelete, String mentod) {
		WalletRecord walletRecord = new WalletRecord();
		
		walletRecord.setPeopleId(peopleId);//该项必填选项
		walletRecord.setIndentId(indentId);//该项必填选项
		walletRecord.setPeopleType(peopleType);//该项必填选项0:商家 1:个人2:工人
		walletRecord.setMainMoney(mainMoney==null?0.00:mainMoney);
		walletRecord.setAddMoney(addMoney==null?0.00:addMoney);
		walletRecord.setSubMoney(subMoney==null?0.00:subMoney);
		walletRecord.setFinalGetMoney(finalGetMoney==null?0.00:finalGetMoney);
		walletRecord.setFinalLostMoney(finalLostMoney==null?0.00:finalLostMoney);
		walletRecord.setType(type);//金钱交易种类0:测量 1:安装 2:维修  3:加价悬赏 4:取消订单(默认值为null)
		walletRecord.setStatus(status==1?status:0);//交易状态0：失败   1：成功
		walletRecord.setRecordTime(new Date());//参数没有传，在这里自己添加
		walletRecord.setIsDelete(isDelete==0?isDelete:1);
		walletRecord.setOrderNo(peopleId+"_"+new Date().getTime());
		walletRecord.setRemark(remark);
		walletRecord.setMethod(mentod);
		
		return walletRecord;
	}
	
	
	
}
